// import { addUser, updataUser, userTpye } from '@/services/userApi';
import {
    ModalForm,
    ProForm,
    ProFormDependency,
    ProFormGroup,
    ProFormSelect,
    ProFormText,
} from '@ant-design/pro-components';
import { useRequest } from '@umijs/max';
import { message } from 'antd';
import React from 'react';

function CrewInfoModel({ data, open = false, onOpenChange, onFinish }: AccountEditDrawerProps) {
    const formRef = React.useRef(null);

    //   const requestAdd = useRequest(addUser, {
    //     manual: true,
    //     onSuccess() {
    //       message.success('新增成功');
    //       onFinish?.();
    //     },
    //     onError() {
    //       message.error('用户名已存在');
    //     },
    //   });
    //   const userList = useRequest(userTpye, {
    //     onSuccess() {},
    //   });
    //   const requestUpdate = useRequest(updataUser, {
    //     manual: true,
    //     onSuccess() {
    //       message.success('编辑成功');
    //       onFinish?.();
    //     },
    //   });
    console.log(data);
    return (
        <ModalForm
            title={'組員記錄'}
            open={open}
            onOpenChange={(open) => onOpenChange?.(open)}
            formRef={formRef}
            modalProps={{
                destroyOnClose: true,
                maskClosable: false,
            }}
            onFinish={async (values) => {
                // 指定对象类型
                const payload: Record<string, string | number> = {
                    ...values,
                    //   password: encryptPwdByMd5(values.password),
                    //   comfirmPassword: encryptPwdByMd5(values.comfirmPassword),
                };
                if (data) {
                    payload.id = data.id;
                    //   await requestUpdate.run(payload);
                    return true;
                }
                // await requestAdd.run(payload);
                return true;
            }}
            initialValues={data as any}
        >
            <ProForm.Group>
                <ProFormText
                    name="userName"
                    width="lg"
                    label="上课地点"
                    fieldProps={{
                        maxLength: 20,
                    }}
                    rules={[{ required: true, message: '请输入' }]}
                    disabled
                ></ProFormText>
            </ProForm.Group>
            <ProForm.Group>
                <ProFormText
                    name="password"
                    width="lg"
                    label="开课课程"
                    fieldProps={{
                        maxLength: 20,
                    }}
                    rules={[{ required: true, message: '请输入' }]}
                    disabled
                ></ProFormText>
            </ProForm.Group>
            <ProForm.Group>
                <ProFormText
                    name="comfirmPassword"
                    width="lg"
                    label="上课班级"
                    fieldProps={{
                        maxLength: 20,
                    }}
                    rules={[{ required: true, message: '请输入' }]}
                    disabled
                ></ProFormText>
            </ProForm.Group>
            <ProForm.Group>
                <ProFormText
                    name="comfirmPassword"
                    width="lg"
                    label="授课教师"
                    fieldProps={{
                        maxLength: 20,
                    }}
                    rules={[{ required: true, message: '请输入' }]}
                    disabled
                ></ProFormText>
            </ProForm.Group>
            <ProFormGroup>
                <ProFormSelect
                    name="roleId"
                    width="sm"
                    label="状态"
                    rules={[{ required: true, message: '请选择' }]}
                    options={[
                        { label: '正常', value: 1 },
                        { label: '异常', value: 2 },
                    ]}
                ></ProFormSelect>
            </ProFormGroup>
        </ModalForm>
    );
}

export type AccountEditDrawerProps = {
    data: Record<string, string> | null;
    open: boolean;
    onOpenChange: Function;
    onFinish?: Function;
};
export default CrewInfoModel;
